package com.t11;

import java.util.*;

/**
 * Created by xuyiwei on 2018/7/22.
 */
public class E12 {
    public static void revece(List<Integer> list) {
        ListIterator<Integer> iterator = list.listIterator();
        //这个迭代器从哪里开始迭代
        ListIterator<Integer> it = list.listIterator(list.size());
        int mid = (list.size()) / 2;
        for (int i = 0; i < mid; i++) {
            int tmp = iterator.next();
            Integer t = it.previous();
            System.out.println(t);
            //因为每次迭代  导致list的前半部分的值已经被覆盖 因此最好的办法  你迭代前半部分  我迭代后半部分
            iterator.set(t);
            it.set(tmp);
        }
    }

    public static void main(String[] args) {
        List<Integer> src =
                Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        List<Integer> dest = new LinkedList<Integer>(src);
        System.out.println("source: " + src);
        System.out.println("destination: " + dest);
        revece(dest);
        System.out.println("source: " + src);
        System.out.println("destination: " + dest);
    }
}
